<?php

/*
 * This file is the jQuery for acknowledge sent screenlet.
 * This handle the transactions of acknowledging that the attachment was received by an external receiver.
 * 
 * Created by: Peter Agno Jr.
 * Date created: October 21, 2011
 */
?>

    // ********************** START - AJAX FOR ACKNOWLEDGE SENT ATTACHMENT SCREENLET **********************
            // Start - Acknowledge that the attachment was received by external receiver 
            jQuery('.ackSentBtn').live("click",function() {
                buttonId = this.id;
                tempSubstr = buttonId.split('_');
            
                // Start - Confirm the user if he/she is sure with the acknowledging the sent attachment
                chosenCnfrm = confirm("Are you sure that the " + jQuery("#attachmentId_"+tempSubstr[1]).val() + " was received?");
                if ( chosenCnfrm == true ) {
                    // Start - Ajax of updating an attachment that it was received externally
                    jQuery.ajax({
                        type : 'POST',
                        url : 'ajaxRequests/acknowledgeSentAttach.php',
                        dataType : 'json',
                        async : false,
                        data: {
                            attachmentId : jQuery("#attachmentId_"+tempSubstr[1]).val()
                        },
                        success : function(data){
                            if ( data.ackSentFlag == "Success" ) {
                                jQuery(".successMessages_"+tempSubstr[1]).html(data.msg);
                                jQuery(".successMessage_"+tempSubstr[1]).show();
                                jQuery("#ackSentAttachScrn_"+tempSubstr[1]).hide();
                                window.scrollTo(0, 0);
                            }
                        },
                        error : function() {
                            alert("Error in acknowledging the attachment was received.");
                        }
                    }); // End -Ajax of updating an attachment that it was received externally
                } // End If, for confirming the acknowledge sent attachment
            }); // End - Acknowledge that the attachment was received by external receiver 
            // ********************** END - AJAX FOR ACKNOWLEDGE SENT ATTACHMENT SCREENLET **********************
